package com.aaa.three.pay;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;

import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

/**
 * @PACKAGE_NAME: com.aaa.three.pay
 * @NAME: Alipay
 * @USER: Tprairie
 * @DATE: 2022/2/22
 * @PROJECT_NAME: three
 */
@Data
@Configuration
public class Alipay {
    public static final Logger logger = LoggerFactory.getLogger(Alipay.class);
    public static final String format = "json";
    public static String appId="2021000119621327";
    public static String privateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDvLRn+ARyPhiZeAraBMwKZOq6xiLCCow5PoNpmGpu9FroWHIBLHONBz/mvjBdsQec8BMKp+IkY1N9Z3iCO91/nVLimqY+oipfiBgydKmjFyl8hamG6DGf2riArJ5dMCCRpEMfQyMN2eEx19SHrRzScDj4NgVhwEzxQnB3i/cKkSNANurG46Ryyyo2Hhs0LGbwt53axwEH9OgsOqCI9F86pDDk0s8JSbnmv3qPMVv0n+qInqxb9EgnJTOpIbdtnSGIvcAugSeoQU7ov2aD32PXytPxieM2IbeVL7nPnY3QTK6BvpxG7YH6GdsTsORW61HgpbCXlUtiXtmRhkysAi4bAgMBAAECggEAIWEEwtYgq/q65zD5aMR4py0eektfkgeKchifAFrli5ZQCl9K0bhq3BnoY8j7Jn8R9Ulbde27OslVa4VBn7PlyeViRRJqVzQAVdo3hiMu6okAoiOJDWB7Ve9Ol2LYfru+UhfY+nPQfoQxSvarX5e92oUYsftEX68Tb/EMjNZpgnuBVe2kyQxtvMKBHUgPzTpXlWKzldWpZ/9c+NwwA8HLUR8wH071KI3ksX4SJeOEmPgY9VsTPDfVFrlojO6oZZXoaPFRBu810kOFl61skqhMjK/fUoOSRpJtEGsIpopLiAtZ+bM13Cv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1BQFnlXby/DhZvWwDqUSaM5rxmDocYvF6/x//QP/9prN/DpgtPNfLdvsLj3SagRzJsJtNK4O8kvMjoXqFYiLu4i5i+XSics8KpD90J829On2DObPLb/s3354M6KX0gGwBvqIZLD+bKppUmfqyGGxX6sPRcnDfc0ZjJHLZAB41JVYmZZTajcBmDQ/LzisHNna8STGy2NAICjDmuDztdH30SDQIDAQAB";
    public static String notifyUrl="http://localhost:8080/demo/doctor/erro.html";
    public static String returnUrl="http://localhost:8080/demo/userr/userResult.html";
    public static String signType="RSA2";
    public static String charset="utf-8";
    public static String gatewayUrl="https://openapi.alipaydev.com/gateway.do";
    public String pay(AliPayBean aliPayBean) throws AlipayApiException {

        AlipayClient alipayClient = new DefaultAlipayClient(
                gatewayUrl, appId, privateKey, format, charset, publicKey, signType);

        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(returnUrl);
        alipayRequest.setNotifyUrl(notifyUrl);
        alipayRequest.setBizContent(JSON.toJSONString(aliPayBean));
        logger.info("封装请求支付宝付款参数为:{}", JSON.toJSONString(alipayRequest));

        String result = alipayClient.pageExecute(alipayRequest).getBody();
        logger.info("请求支付宝付款返回参数为:{}", result);

        return result;
    }
}
